<?php
/**
 * 后台设置用户对应平台银行卡操作模型
 */
class MSetBank extends MY_Model {
	protected $table = 'user';
	function __construct() {
		parent::__construct();
	}
	
	public function getList($limit, $sort=false){
		$this->db->select($this->table.'.account,'.$this->table.'.id,bank_info.code,bank_info.bank');
		$this->db->distinct();
		$this->db->from($this->table);
		$this->db->join('bank_info', $this->table.'.set_bank_code=bank_info.code','LEFT');
		if($limit){
			$this->db->limit($limit['limit'],$limit['offset']);
		}
		$this->formfilter->doFilter();
		if($sort){
			$this->db->order_by($this->table.'.id', 'asc');
		}else{
			$this->db->order_by($this->table.'.id', 'desc');
		}
		$query = $this->db->get();
		return $query->result();
	}
	
	public function getCount(){
		$this->db->select('count(distinct '.$this->db->dbprefix($this->table).'.id) as num');
		$this->db->from($this->table);
		$this->db->join('bank_info', $this->table.'.set_bank_code=bank_info.code','LEFT');
		$this->formfilter->doFilter();
		$tmp = $this->db->get()->result();
		return (int)$tmp[0]->num;
	}
	
	public function updateBankCode($set_bank_code,$userIdArr){
	    $this->db->set('set_bank_code',$set_bank_code);
	    $this->db->where_in('id',$userIdArr);
	    return $this->db->update($this->table);
	}

}
